var scrollTop = function () {
  return Math.max(document.body.scrollTop, document.documentElement.scrollTop)
}

var documentHeight = function () {
  return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
}

var windowHeight = function () {
  return (document.compatMode === 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight
}

var ua = window.navigator.userAgent.toLowerCase()

module.exports = {
  touchBottom () {
    return scrollTop() + windowHeight() + 1 >= documentHeight()
  },
  scrollBottom () {
    document.body.scrollTop = scrollTop() + windowHeight()
  },
  scrollTop () {
    document.body.scrollTop = 0
  },
  isWechat () {
    if (ua.indexOf('micromessenger') > 0) {
      return true
    } else {
      return false
    }
  },
  isWeibo () {
    if (ua.indexOf('weibo') > 0) {
      return true
    } else {
      return false
    }
  },
  isIphone () {
    if (ua.indexOf('iphone') > 0) {
      return true
    } else {
      return false
    }
  }
}
